<?php

namespace StrategyPattern;

include_once "StrategyInterface.php";

/** 策略模式的上下文类 */
class Context
{
    /** @var StrategyInterface 存储策略对象 */
    public StrategyInterface $strategyObject;

    /**
     * 初始化 $strategyObject
     * @param StrategyInterface $strategy
     */
    public function __construct(StrategyInterface $strategy)
    {
        $this->strategyObject = $strategy;
    }

    /**
     * 策略模式统一执行具体策略类的方法
     * @return mixed
     */
    public function contextStrategy()
    {
        return $this->strategyObject->algorithm();
    }
}